import { Link, Warning, RepoLink } from '@brillout/docpress'
import { ConfigSpec } from '../../components'

<ConfigSpec
  env="client, server"
  global
/>

The `onBeforeRoute()` hook provides full control over routing.

It is usually used for [internationalization](/i18n):

```ts
// Environment: server & client

export { onBeforeRoute }

import type { PageContext } from 'vike/types'

function onBeforeRoute(pageContext: PageContext) {
  const { urlWithoutLocale, locale } = extractLocale(pageContext.urlPathname)
  return {
    pageContext: {
      locale,
      urlLogical: urlWithoutLocale
    }
  }
}
```

You can also use it to [implement a custom router](https://github.com/vikejs/vike/issues/140).

<Warning>For use cases other than i18n, open a GitHub ticket or reach out on Discord: `onBeforeRoute()` is purposely limited but the limitations can be lifted in order to unlock new capabilities.</Warning>


## See also

- <Link href="/routing" />
- <Link href="/hooks" />
